package org.example.infrastructure.persistence.remote.fallbackFactory;

import org.example.domain.model.entity.url.resp.QueryGroupByCountResp;
import org.example.infrastructure.persistence.remote.RemoteUrlShortenerPersistence;
import org.example.web.exception.ServerException;
import org.example.web.result.ResultInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteUrlShortenerFallbackFactory implements FallbackFactory<RemoteUrlShortenerPersistence> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUrlShortenerFallbackFactory.class);

    @Override
    public RemoteUrlShortenerPersistence create(Throwable cause) {

        return new RemoteUrlShortenerPersistence() {
            @Override
            public ResultInfo<List<QueryGroupByCountResp>> queryGroupByCount(List<String> gidList) {
                log.error("获取分组下的短链接数量失败！");
                throw new ServerException("获取分组下的短链接数量失败！");
            }
        };
    }
}
